<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<title>省市级联->ajax实现</title>
<script type="text/javascript">
   $(function(){
	        //定位省份下拉框，同时添加内容改变事件
	       $("#province").change(function(){
		   //清空原城市下拉框的内容，除第一项外
		   $("#city option:gt(0)").remove();
		   //获取选中的省份
		   var province=$("#province option:selected").text();
		   if("请选择省份"!=province){
			   $.ajax({
				 type:"POST",
				 url:"findCity?time="+new Date().getTime(),
			     data:{"province":province},
			     success:function(backDate,textStatus,ajax){
			    	 var array=backDate.cityList;
			    	 var size=array.length;
			    	 for(var i=0;i<size;i++){
			    		var city=array[i];
			    		var $option=$("<option>"+city+"</option>");
			    		$("#city").append($option);
			    	 } 
			     }
			   });
		   }
	   });
   })
</script>
</head>
<body>
     <select id="province">
          <option>请选择省份</option>
          <option>河南</option>
          <option>山东</option>
          <option>江苏</option>
     </select>
     <select id="city">
          <option>请选择城市</option>
     </select>
</body>
</html>